package com.estate.report.scheduler;

import com.estate.common.utils.DateUtils;
import com.estate.report.service.IDataStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import java.util.Date;

@Configuration
@EnableScheduling
@Slf4j
public class StatisticsScheduler {

    @Resource
    IDataStatisticsService dataStatisticsService;

    /**
     * 生成统计数据
     * 每天1点执行
     */
    @Scheduled(cron = "0 0 1 * * ?")
    private void genStatisticsData() {
        log.info("开始生成统计数据");
        Date today = DateUtils.getNowDate();
        Date yesterday = DateUtils.addDays(today, -1);
        dataStatisticsService.genStatisticsData(yesterday, yesterday);
        log.info("生成统计数据完成");
    }
}
